home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-09-17 | 4.4 KB | 138 lines | [TEXT/MPS ] |
- ###################################################################################################
- #
- # Copyright © 1990 Apple Computer, Inc. All rights reserved.
- # Copyright © 1990 Kevin O'Mahoney, All rights reserved.
- #
- # File: MakeTheFolder
- #
- #
- ###################################################################################################
- #
- # Abstract:
- #
- # This script was developed to help in the building of BART project as part of the Service Tools
- # diagnostic projects.
- #
- # This script accepts one input parameter. This is the name of a folder to be created. Whereas
- # the MPW command NewFolder will also create folders, the NewFolder command will not create a
- # named folder if all of it's parent folders do not already exist. This script will insure all
- # folders in the path exist. So this script may be called once using the full pathname of the
- # desired folder and this script will create all needed parent folders along the path and then
- # the target folder itself.
- #
- # If the folder already exists then no action is taken.
- #
- ###################################################################################################
- #
- # Usage:
- # MakeTheFolder folderName
- #
- #
- ###################################################################################################
- #
- # Change History:
- #
- # 11 Nov 1991 - KOM - new today
- # 19 Nov 1991 - KOM - rewritten and made more robust in error handling
- #
- ###################################################################################################
-
- Set ErrorCode 0; # no errors yet
-
- #-------------------------------------------# turn off echo
- Set savedEchoState "{Echo}";
- #Set Echo 0;
-
- Set UsageString "# Usage - “{0} folderName”"
- Set EchoPrefix "# {0} - ";
-
- #Echo " "
- #Echo "{EchoPrefix}Parameters count={#} params=“{Parameters}”";
-
- If ( {#} == 0 )
- Echo "### {0} - no folder name specified." > Dev:StdErr
- Echo "{UsageString}" > Dev:StdErr
- Set ErrorCode 1;
- Else If ( {#} > 1 )
- Echo "### {0} - too many parameters." > Dev:StdErr
- Echo "{UsageString}" > Dev:StdErr
- Set ErrorCode 2;
- End;
-
- #---------------------------------------------------------------------------------------------------
- If "{1}" =~ /:(≈)®1/ # strip off leading colon till we need it
- Set toFolderName "{®1}";
- #Set kLeadingColon ":"; # remember the leading colon
- Set kLeadingColon "`Directory`"; # remember the leading colon along with the full path name to here
- Else
- Set toFolderName "{1}";
- Set kLeadingColon ""; # there was no leading colon
- End;
-
- #---------------------------------------------------------------------------------------------------
- #Echo "{EchoPrefix}toFolderName = “{toFolderName}”, kLeadingColon=“{kLeadingColon}”";
- #Echo;
-
- #---------------------------------------------------------------------------------------------------
- Set kFolderToMake "{toFolderName}";
- Set kBuildUpname "";
-
- Loop;
- Break If ( {ErrorCode} != 0 );
- Set ®1 "";
- Set ®2 "";
- ( Evaluate "{kFolderToMake}" =~ /([¬:]+:)®1(≈)®2/ ) > Dev:Null;
- Set k1 "{®1}""";
- Set k2 "{®2}""";
- #Echo "{EchoPrefix}(loop) k1 = “{k1}”, k2 = “{k2}”";
-
- Set kBuildUpname "{kBuildUpname}{k1}";
- Set kFolderToMake "{k2}";
- #Echo "{EchoPrefix}(loop2) “{kBuildUpname} - {kFolderToMake}” kBuildUpname - kFolderToMake ";
- #Echo "{EchoPrefix} - NewFolder {kLeadingColon}{kBuildUpname}";
-
- Loop
- If Not "`Exists "{kLeadingColon}{kBuildUpname}"`"
- #Echo "Creating Folder: “{kLeadingColon}{kBuildUpname}”.";
- NewFolder "{kLeadingColon}{kBuildUpname}";
- If `Exists "{kLeadingColon}{kBuildUpname}"` # did we create it?
- Break;
- Else;
- Echo "### Error, {0} - Unable to create target folder, “{kLeadingColon}{kBuildUpname}”.";
- Set ErrorCode 4;
- Break;
- End;
-
- Break;
- Else
- If Not "`Exists -d "{kLeadingColon}{kBuildUpname}"`"
- ( Evaluate "{kLeadingColon}{kBuildUpname}" =~ /(≈)®1:/ ) > Dev:Null;
- Echo "### Error in {0}: Trying to make folder but found a file “{®1}”."
- {MAFailed}
- Set ErrorCode 3;
- Break;
- Else
- #Echo "{EchoPrefix}found folder";
- Break;
- End
- End;
- End;
-
-
-
- If "{k2}" == ""
- #Echo "{EchoPrefix}(loop) break, k2 is blank, no more parent folders."
- Break;
- End;
- #Echo;
- End; Unset ®1; Unset ®2;
-
- #Echo "{EchoPrefix}(loop) kFolderToMake = “{kFolderToMake}” on the way out of loop.";
-
-
- #------------------------------------------------------------# restore echo state
- Set Echo "{savedEchoState}";
- Unset savedEchoState;
-
- #Echo "{EchoPrefix}ErrorCode = “{ErrorCode}”";
- Exit {ErrorCode};